import http from "@/api";
import { PORT1 } from "@/api/config/servicePort";
import { Common } from "@/api/interface/common";

/** 获取学校学期列表 */
export const getSchoolSemesterList = () => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/semester/GetSchoolSemesterList');
};

// 获取学校列表
export const GetSchoolList = (params: Common.ReqCommonList) => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/school/GetSchoolList', params);
};

/** 获取分类列表 */
export const getCategoryList = () => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/category/GetCategoryList');
};

/** 获取角色列表 */
export const getRoleList = (params: Common.ReqCommonList) => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/role/GetRoleList', params);
};

/** 获取学校年级列表 */
export const getSysGradeList = () => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/sysGrade/GetSysGradeList');
}
/** 获取年级列表 */
export const getClassGradeList = () => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/class/GetClassGradeList');
};

/** 获取班级列表 */
export const getClassList = (params: Common.ReqGetClassList) => {
	return http.get<Common.ResCommon>(PORT1 + '/admin/class/GetClassList', params, { noLoading: true });
};

/** 获取年级班级层级列表 */
export const getGradeClassTree = async () => {
	const { data }: any = await http.get(PORT1 + '/admin/class/GetGradeClassTree');
  data.forEach((item: any) => {
    item.label = item.gradeName
    item.value = item.gradeCode
    if (item.classList && item.classList.length) {
      item.children = item.classList
      item.children.forEach((child:any) => {
        child.label = child.className
        child.value = child.classId
      })
    }
  })
  return Promise.resolve({ data: { list: data }})
};

/** 获取阿里云oss签名 */
export const getOssSignature = (params: Common.ReqOssSignature) => {
	return http.post(PORT1 + '/admin/auth/GetOssSignature', params);
};

/** 上传文件/图片 */
export const upload = async (params: any) => {
  return http.post(process.env.NODE_ENV === "production" ? params.host : params.host, params.fd, { headers: { "content-type": "multipart/form-data", "X-Requested-With": "XMLHttpRequest" } });
};

/** 获取导入模板 */
export const getImportTemplate = (params: any) => {
	return http.get(PORT1 + `/admin/common/GetImportTemplate`, params);
};